<template>
  <div class="viewer">
    <div class="markdown-body" v-html="htmlCode"></div>
  </div>
</template>

<script setup lang="ts">
import { ref, watch } from "vue";
import markdownIt from "markdown-it";

const md = new markdownIt();

const props = defineProps({
  code: {
    type: String,
    default: "",
  },
});

const htmlCode = ref("");

watch(
  () => props.code,
  (newValue) => {
    htmlCode.value = md.render(newValue);
  },
  {
    immediate: true,
  }
);
</script>

<style>
.viewer {
  position: absolute;
  padding: 5px 10px 5px 10px;
  left: 5px;
  right: 10px;
  top: 10px;
  bottom: 10px;
  overflow-y: auto;
  background-color: #ffffff;
}
</style>
